﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSConsoleTest
{
    class TestGenericBasic : BaseConsoleTest
    {
        public void printDescription()
        {
            Console.WriteLine("--- Generic basic ---");
        }

        public void doTest()
        {
            TestWord word = new TestWord() { TextContent = "ABCabc" };
            TestExcel excel = new TestExcel() { TextContent = "Sheet" };
            TestPowerpoint ppt = new TestPowerpoint() { TextContent = "Slide" };

            TestDocumentPrinter<TestDocument> docPrinter = new TestDocumentPrinter<TestDocument>();
            docPrinter.Document = word;
            docPrinter.launch();
            docPrinter.Document = excel;
            docPrinter.launch();
            docPrinter.Document = ppt;
            docPrinter.launch();
        }
    }

    interface IPrintable 
    {
        void print();
    }

    abstract class TestDocument : IPrintable
    {
        public string TextContent
        {
            get;
            set;
        }

        public abstract void print();
    }

    class TestWord : TestDocument
    {
        public override void print()
        {
            Console.WriteLine("Word : {0}", TextContent);
        }
    }

    class TestExcel : TestDocument
    {
        public override void print()
        {
            Console.WriteLine("Excel : {0}", TextContent);
        }
    }

    class TestPowerpoint : TestDocument
    {
        public override void print()
        {
            Console.WriteLine("Powerpoint : {0}", TextContent);
        }
    }

    class TestDocumentPrinter<T> where T : IPrintable
    {
        public T Document
        {
            get;
            set;
        }

        public void launch()
        {
            if (Document == null)
            {
                Console.WriteLine("There is no document to print");
            }
            else
            {
                Document.print();
            }
        }

    }
}
